package com.example.wisdomclassroomapi.domain.repository;

import com.example.wisdomclassroomapi.domain.entity.RecordStudentLearnEntity;
import com.example.wisdomclassroomapi.infrastructure.mapper.RecordStudentLearnMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;
/**
 * @Package: com.example.wisdomclassroomapi.domain.repository
 * @Description: <>
 * @Author: scholes
 * @CreateDate: 2022-04-19
 * @UpdateUser: scholes
 * @UpdateDate: 2022-04-19
 * @UpdateRemark: <>
 * @Version: 1.0
 */
@Repository
public class RecordStudentLearnRepository {
    @Resource
    private RecordStudentLearnMapper recordStudentLearnMapper;

    public void add(RecordStudentLearnEntity entity) {
       recordStudentLearnMapper.insert(entity);
    }

    public RecordStudentLearnEntity findById(String id) {
        return recordStudentLearnMapper.selectById(id);
    }

    public int updateById(RecordStudentLearnEntity entity) {
        return recordStudentLearnMapper.updateById(entity);
    }

    public int deleteById(String id) {
        return recordStudentLearnMapper.deleteById(id);
    }

    public IPage<RecordStudentLearnEntity> page(RecordStudentLearnEntity entity,IPage page) {
        QueryWrapper<RecordStudentLearnEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getSutdentId())){
            wrapper.eq("sutdent_id",entity.getSutdentId());
            }
            if (StringUtils.isNotBlank(entity.getSubjectId())){
            wrapper.eq("subject_id",entity.getSubjectId());
            }
            if (StringUtils.isNotBlank(entity.getLessonId())){
            wrapper.eq("lesson_id",entity.getLessonId());
            }
            if (StringUtils.isNotBlank(entity.getLessonPeriodId())){
            wrapper.eq("lesson_period_id",entity.getLessonPeriodId());
            }
            if (entity.getProgress()!=null){
            wrapper.eq("progress",entity.getProgress());
            }
            if (entity.getDuration()!=null){
            wrapper.eq("duration",entity.getDuration());
            }
        return recordStudentLearnMapper.selectPage(page, wrapper);
    }

    public List<RecordStudentLearnEntity> list(RecordStudentLearnEntity entity) {
        QueryWrapper<RecordStudentLearnEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getSutdentId())){
            wrapper.eq("sutdent_id",entity.getSutdentId());
            }
            if (StringUtils.isNotBlank(entity.getSubjectId())){
            wrapper.eq("subject_id",entity.getSubjectId());
            }
            if (StringUtils.isNotBlank(entity.getLessonId())){
            wrapper.eq("lesson_id",entity.getLessonId());
            }
            if (StringUtils.isNotBlank(entity.getLessonPeriodId())){
            wrapper.eq("lesson_period_id",entity.getLessonPeriodId());
            }
            if (entity.getProgress()!=null){
                wrapper.eq("progress",entity.getProgress());
            }
            if (entity.getDuration()!=null){
                wrapper.eq("duration",entity.getDuration());
            }
        return recordStudentLearnMapper.selectList(wrapper);
    }

}